package com.ruoyi.topInsectImg.utils;

import com.alibaba.fastjson.JSON;
import com.ruoyi.topInsectImg.domain.Device;
import com.ruoyi.topInsectImg.domain.InsectImg;
import com.ruoyi.topInsectImg.domain.StationList;
import com.ruoyi.topInsectImg.domain.Terminal;
import com.ruoyi.topInsectImg.utils.soa.SOAClient;
import com.ruoyi.topInsectImg.utils.soa.SOAResponse;
import com.ruoyi.topInsectImg.utils.soa.SOAResponseList;


import java.util.List;
import java.util.Map;

/**
 * Top-API接口调用封装类
 * 获取测报灯图片
 * @author Mr-Le
 */
public class TopInsect {

    /**
     * 1.登录API接口
     *
     * @param params 参数，存放user_name、password
     * @return SOAResponse:内含 result 结果
     */
    public SOAResponse topLogin(Map<String, Object> params) {
        return SOAClient.rpcCall("top.aiot.user.login", "v1.0", "post", params);
    }

    /**
     * 2.获取基地列表
     *
     * @param params 参数 station_id
     * @return List集合，存放基地列表
     */
    public List<StationList> getStationList(Map<String, Object> params) {
        SOAResponse soaResponse = SOAClient.rpcCall("top.aiot.station.list", "v1.0", "get", params);
        return JSON.parseArray(soaResponse.getResult().get("datalist").toString(), StationList.class);
    }

    /**
     * 3.获取基地下所有终端列表
     *
     * @param params
     * @return
     */
    public List<Terminal> getTerminal(Map<String, Object> params) {
        SOAResponseList soaResponseList = SOAClient.rpcCallList("top.aiot.station.terminallist", "v1.0", "get", params);
        return JSON.parseArray(soaResponseList.getResult().toString(), Terminal.class);
    }

    /**
     * 4.获取终端下设备列表
     *
     * @param params 增加 terminal_id
     * @return 返回设备列表
     */
    public List<Device> getDevice(Map<String, Object> params) {
        SOAResponseList soaResponseList = SOAClient.rpcCallList("top.aiot.terminal.device", "v1.0", "get", params);
        return JSON.parseArray(soaResponseList.getResult().toString(), Device.class);
    }


    /**
     * 5.根据设备ID，查找图片
     *
     * @param params 增加
     *               device_id: 设备
     *               start_date: 开始时间(yyyyMMddHHmmss)
     *               end_date: 结束时间(yyyyMMddHHmmss)
     * @return
     */
    public List<InsectImg> getInsectImg(Map<String, Object> params) {
        SOAResponseList soaResponseList = SOAClient.rpcCallList("top.aiot.ext.insect.img.list", "v1.0", "get", params);
        return JSON.parseArray(soaResponseList.getResult().toString(), InsectImg.class);
    }




}
